package www.openteam.com.adapter.PrdctnMngmnt;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import www.openteam.com.R;
import www.openteam.com.bean.SRCPoduMsg;

/**
 * Created by Administrator on 2019-06-19.
 */

public class SRCKPoduAdp extends RecyclerView.Adapter<SRCKPoduAdp.ViewHolder> {
    Context context;
    List<SRCPoduMsg.DataBeanX.DataBean> dataBeanList = new ArrayList<>();
    SRCKPoduClickBack srckPoduClickBack;
    double mClickTime =0;

    public interface SRCKPoduClickBack{
        void postdata(SRCPoduMsg.DataBeanX.DataBean dataBean);
    }

    public void setSrckPoduClickBack(SRCKPoduClickBack srckPoduClickBack) {
        this.srckPoduClickBack = srckPoduClickBack;
    }

    public SRCKPoduAdp(Context context, List<SRCPoduMsg.DataBeanX.DataBean> dataBeanList) {
        this.context = context;
        this.dataBeanList = dataBeanList;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_srck_podu, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        final SRCPoduMsg.DataBeanX.DataBean dataBean = dataBeanList.get(position);
        holder.srckPoduPjctNum.setText(dataBean.getPojectNum());
        holder.srckPoduPjctCode.setText(dataBean.getPojectCode());
        holder.srckPoduUnit.setText(dataBean.getUnit());
        holder.srckPoduAmount.setText(dataBean.getAmount()+"");
        holder.srckPoduIssueNum.setText(dataBean.getIssueNum());
        holder.srckPoduPjctReq.setText(dataBean.getPocessReq());
        holder.srckPoduOtherState.setText(dataBean.getOtherState());
        holder.srckPoduParts.setText(dataBean.getPPID()+"");
        holder.srckPoduPoduce.setText(dataBean.getPoduce());
        holder.srckPoduPoduceName.setText(dataBean.getPoduceName());
        holder.srckPoduLine.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (System.currentTimeMillis() - mClickTime <600) {
                    if (null!=srckPoduClickBack){
                        srckPoduClickBack.postdata(dataBean);
                    }
                } else {
                    mClickTime = System.currentTimeMillis();
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return dataBeanList.size();
    }


    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.srck_podu_pjctNum)
        TextView srckPoduPjctNum;
        @Bind(R.id.srck_podu_pjctCode)
        TextView srckPoduPjctCode;
        @Bind(R.id.srck_podu_pjctName)
        TextView srckPoduPjctName;
        @Bind(R.id.srck_podu_Unit)
        TextView srckPoduUnit;
        @Bind(R.id.srck_podu_parts)
        TextView srckPoduParts;
        @Bind(R.id.srck_podu_amount)
        TextView srckPoduAmount;
        @Bind(R.id.srck_podu_issueNum)
        TextView srckPoduIssueNum;
        @Bind(R.id.srck_podu_pjctReq)
        TextView srckPoduPjctReq;
        @Bind(R.id.srck_podu_otherState)
        TextView srckPoduOtherState;
        @Bind(R.id.srck_podu_line)
        LinearLayout srckPoduLine;
        @Bind(R.id.srck_podu_poduce)
        TextView srckPoduPoduce;
        @Bind(R.id.srck_podu_poduceName)
        TextView srckPoduPoduceName;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
